package com.cne.gmail.Gmail.Excutor;


import com.cne.gmail.Gmail.Handle.GmailHandle;
import com.cne.gmail.Gmail.model.UserModel;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.model.WatchRequest;
import com.google.api.services.gmail.model.WatchResponse;

import java.util.List;
import java.util.concurrent.Callable;

public class WatchUserMailExcutor implements Callable {
    private UserModel user;
    private List listLabel;
    public WatchUserMailExcutor(UserModel user, List listLabel){
        this.listLabel=listLabel;
        this.user=user;
    }

    @Override
    public UserModel call() throws Exception {
        Gmail service= GmailHandle.service(user);
        WatchRequest watchRequest=new WatchRequest();
        watchRequest.setTopicName("projects/myproject-221302/topics/cne-topic");
        watchRequest.setLabelIds(listLabel);
        watchRequest.setLabelFilterAction("include");
        WatchResponse response=     service.users().watch("me",watchRequest).execute();
        this.user.setHistoryId(String.valueOf(response.getHistoryId()));
        return user;
    }
}
